fix: handle gh pr merge in worktree context#4
Merged
Conversation
When /ship runs from a git worktree, commands like `git checkout`, `gh pr merge --delete-branch`, and `git branch -D` fail because worktrees cannot freely switch branches. This adds worktree detection (checking if .git is a file rather than a directory) and adapts: - Phase 6 merge: use remote-only strategy, fetch instead of checkout - Phase 11 cleanup: skip local branch ops in worktree mode - Cancel/cleanup: close PR and delete remote branch separately - Deployment (Phase 9): block with clear error, require main repo - Rollback: block with clear error, require main repo
- Get merge SHA from PR metadata instead of fetch (avoids race condition) - Add OWNER/REPO validation before merge command - Move worktree checks before output in deployment/rollback - Add fallback worktree detection in Phase 11 cleanup - Surface branch deletion warnings instead of silent suppression - Add 2>/dev/null to git rev-parse in error paths - Include main repo path in deployment error messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gh pr merge --repowithout--delete-branchwhen in worktree (avoidsfatal: 'main' is already used by worktree)Test Plan
.gitis a file in worktree (detection logic):[ -f "$(git rev-parse --show-toplevel)/.git" ]/shipfrom a worktree created by/next-task- merge should complete without checkout error/shipfrom a normal clone - behavior should be unchangedCloses #3